﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Xml.Linq;
using System.Net.NetworkInformation;

namespace 美妆产品管理系统.caigous
{
    public partial class cgdd : Form
    {
        public cgdd()
        {
            InitializeComponent();
            
        }
        public static string path_source = "";
        SqlDataAdapter dacaigou, dalog;
        DataSet ds = new DataSet();
        void init()//初始化
        {
            DB.GetCn();
            string str = "select * from caigou ";
            string sdr = "select * from Tlog";
            dacaigou = new SqlDataAdapter(str, DB.cn);
            dalog = new SqlDataAdapter(sdr, DB.cn);
            dacaigou.Fill(ds, "cg_info");
            dalog.Fill(ds, "log_info");
        }
        void showAll()
        {
            DataView dvcg = new DataView(ds.Tables["cg_info"]);
            dataGridView1.DataSource = dvcg;
        }
        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void cgdd_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“salesDataSet9.Category”中。您可以根据需要移动或移除它。
            this.categoryTableAdapter.Fill(this.salesDataSet9.Category);
            // TODO: 这行代码将数据加载到表“salesDataSet5.Supplier”中。您可以根据需要移动或移除它。
            this.supplierTableAdapter.Fill(this.salesDataSet5.Supplier);
            init();
            showAll();
        }

        private void btnok_Click(object sender, EventArgs e)
        {
            if (txtid.Text == "" || txtmoney.Text == "" || txtname.Text == "" || txtnember.Text == "")
            {
                MessageBox.Show("必填项不能为空");
            }
            else
            {
                DB.GetCn();
                string str = "insert into caigou values('" + txtid.Text + "','"
                              + txtname.Text + "','" + cbxsupp.SelectedValue + "','" + txtnember.Text + "','"
                              + txtmoney.Text + "',null,'未审核','" + cbxlb.SelectedValue + "')";
                DB.sqlEx(str);

                DataRow drLog = ds.Tables["log_info"].NewRow();
                drLog["username"] = Login.username;
                drLog["type"] = "添加";
                drLog["action_date"] = DateTime.Now;
                drLog["action_table"] = "caigou表";
                ds.Tables["log_info"].Rows.Add(drLog);

                try
                {
                    SqlCommandBuilder dbcaigouss = new SqlCommandBuilder(dacaigou);
                    dacaigou.Update(ds, "cg_info");
                    SqlCommandBuilder dbLog = new SqlCommandBuilder(dalog);
                    dalog.Update(ds, "log_info");
                    MessageBox.Show("已提交");
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                DB.cn.Close();
                this.Close();
            }

            }

        private void btnno_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
